package com.youlai.system.controller;

import com.youlai.system.common.result.Result;
import com.youlai.system.model.entity.AirSeat;
import com.youlai.system.service.AirSeatService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @Author Ricardo
 * @Date 2024/10/24 15:25
 * @注释
 */
@Tag(name = "15.座位信息接口")
@RestController
@RequestMapping("/api/v1/seat")
@RequiredArgsConstructor
public class AirSeatController {
    @Autowired
    private AirSeatService airSeatService;

    //添加或修改座位表
    @PostMapping("/add")
    public Result addSeat(@RequestBody List<AirSeat> airSeats){
        if (airSeatService.saveOrUpdateBatch(airSeats)){
            return Result.success();
        }else {
            return Result.failed();
        }
    }
    @PutMapping("/delete")
    public Result deletePlaneInformation(long plane_id){
        if (airSeatService.removeById(plane_id)){
            return Result.success();
        }else {
            return Result.failed();
        }
    }

    @GetMapping("/select")
    public Result<List<AirSeat>> searchPlaneInformation(){
        if (airSeatService.list()!=null){
            return Result.success(airSeatService.list());
        }else {
            return Result.failed();
        }
    }
    @GetMapping("/select/{planeId}")
    public Result<AirSeat> getSeatType(@PathVariable long planeId){
        System.out.println("飞机座位类型请求"+planeId);
        AirSeat airSeat = airSeatService.getById(planeId);
        if (airSeat!=null){
            return Result.success(airSeat);
        }else {
            return Result.failed();
        }
    }


}
